﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Model;
using Bll;
using System.Data;

namespace Accounting
{
    public partial class index : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DataShow();
                NavLiCss();


            }
        }

        public void DataShow()
        {
            BllIndex b = new BllIndex();
            DataTable dtNav = b.Nav_Name_Display();
            DataTable bSubNav3 = b.Major_SubNav_Name_All();

            //专业介绍图标按钮开始

            RpProfessional.DataSource = bSubNav3;
            RpProfessional.DataBind();
            
            //专业介绍图标按钮结束
            

            //图片滚播图开始
            DataTable dtImg = b.IndexImg2();

            int a = dtImg.Rows.Count;
            if (a == 1)
            {
                ImgTitle1.Visible = true;
            }
            else if (a == 2)
            {
                ImgTitle1.Visible = true;
                ImgTitle2.Visible = true;
            }
            else if (a == 3)
            {
                ImgTitle1.Visible = true;
                ImgTitle2.Visible = true;
                ImgTitle3.Visible = true;
            }
            else if (a == 4)
            {
                ImgTitle1.Visible = true;
                ImgTitle2.Visible = true;
                ImgTitle3.Visible = true;
                ImgTitle4.Visible = true;
            }
            else if (a == 5)
            {
                ImgTitle1.Visible = true;
                ImgTitle2.Visible = true;
                ImgTitle3.Visible = true;
                ImgTitle4.Visible = true;
                ImgTitle5.Visible = true;
            }
            else if (a == 6)
            {
                ImgTitle1.Visible = true;
                ImgTitle2.Visible = true;
                ImgTitle3.Visible = true;
                ImgTitle4.Visible = true;
                ImgTitle5.Visible = true;
                ImgTitle6.Visible = true;
            }

            Repeater1.DataSource = dtImg;
            Repeater1.DataBind();

            //图片滚播图结束

            //模块最新6条开始
            Module_Information.DataSource = b.Module_Nav_Information();
            Module_Information.DataBind();
            //模块最新6条结束

            //通知公告最新12条开始


            DataTable dtNotice = b.Notice_Information();
            RPNotice.DataSource = dtNotice;
            RPNotice.DataBind();
            int i = 0;
            foreach(DataRow my in dtNotice.Rows)
            {
                
                Label lblNotice = (Label)RPNotice.Items[i].FindControl("lblid");
                if(my["type"].ToString()=="0")
                {
                    lblNotice.Text = "周行事历 | ";
                }
                if (my["type"].ToString() == "1")
                {
                    lblNotice.Text = "通知公告 |";
                }

                    if (my["Important"].ToString()=="True")
                {
                    lblNotice.CssClass = "colorred";
                }
                i++;
            }
            //通知公告最新12条结束

            
            RpServise.DataSource = b.Servise_All();
            RpServise.DataBind();
        }

        public void NavLiCss()
        {
            ((System.Web.UI.HtmlControls.HtmlGenericControl)Master.FindControl("LiNavName1")).Attributes.Add("class", "LiNavNameSelectedCss");
            ((System.Web.UI.HtmlControls.HtmlGenericControl)Master.FindControl("LiNavName2")).Attributes.Add("class", "LiNavNameCss");
            ((System.Web.UI.HtmlControls.HtmlGenericControl)Master.FindControl("LiNavName3")).Attributes.Add("class", "LiNavNameCss");
            ((System.Web.UI.HtmlControls.HtmlGenericControl)Master.FindControl("LiNavName4")).Attributes.Add("class", "LiNavNameCss");
            ((System.Web.UI.HtmlControls.HtmlGenericControl)Master.FindControl("LiNavName5")).Attributes.Add("class", "LiNavNameCss");
            ((System.Web.UI.HtmlControls.HtmlGenericControl)Master.FindControl("LiNavName6")).Attributes.Add("class", "LiNavNameCss");
            ((System.Web.UI.HtmlControls.HtmlGenericControl)Master.FindControl("LiNavName7")).Attributes.Add("class", "LiNavNameCss");
            ((System.Web.UI.HtmlControls.HtmlGenericControl)Master.FindControl("LiNavName8")).Attributes.Add("class", "LiNavNameCss");
            ((System.Web.UI.HtmlControls.HtmlGenericControl)Master.FindControl("LiNavName9")).Attributes.Add("class", "LiNavNameCss");
        }
        
        protected void lbtnPiece2_Click(object sender, EventArgs e)
        {
            Response.Redirect("./Piece.aspx?type=3&nav=12&Web=&Ntype=1");
        }
        
        protected void Module_Information_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            BllIndex b = new BllIndex();

            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Repeater Module_Information_list = e.Item.FindControl("Module_Information_list") as Repeater;
                DataRowView rowv = (DataRowView)e.Item.DataItem;
                int id = Convert.ToInt32(rowv["Id"]);
                ModelIndex m = new ModelIndex();
                m.Id = id;

                Module_Information_list.DataSource = b.Module_Content_Information(m);
                Module_Information_list.DataBind();
            }
        }

        protected void RpProfessional_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            Label lblName = (Label)e.Item.FindControl("lblName");
            Response.Redirect("./Piece.aspx?type=2&Nav=3&name=" + lblName.Text + "&Web=");
        }

        protected void Module_Information_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            Label lblId = (Label)e.Item.FindControl("lblId");
            Response.Redirect("./Piece.aspx?type=1&Nav="+ lblId.Text + "&Web=");
        }
    }
}